//
//  SISSImportantMattersNotiShowViewController.m
//  SISSAPP
//
//  Created by 袁应荣 on 2019/7/4.
//  Copyright © 2019 优房网. All rights reserved.
//

#import "SISSImportantMattersNotiShowViewController.h"
#import "SISSUploadImportantMattersNotiViewController.h"
#import "SISSNetworkingManager+Progress.h"
#import "SISSHouseProgressModel.h"
#import "SISSHouseProgressRecordInfoModel.h"
#import "SISSPassengerProgressModel.h"
#import "SISSPassengerProgressRecordInfoModel.h"
#import "SISSSellerImportantNotiModel.h"
#import "SISSBuyerImportantNotiModel.h"

@interface SISSImportantMattersNotiShowViewController ()

///
@property (strong, nonatomic) SISSSellerImportantNotiModel *sellerImportantNotiModel;
@property (strong, nonatomic) SISSBuyerImportantNotiModel *buyerImportantNotiModel;

@end

@implementation SISSImportantMattersNotiShowViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = self.isSellerNoti ? @"二手房交易卖方重要事项告知书" : @"二手房交易买方重要事项告知书";
    self.uploadImageShowView.titleStr = self.isSellerNoti ? @"卖方重要事项告知书电子档图片" : @"买方重要事项告知书电子档图片";
    
    [self requestImportantNotiInfoData];
}

- (void)requestImportantNotiInfoData {
    WeakSelf

    if (self.isSellerNoti) {
        NSString *ahbpId = self.houseProgressModel ? self.houseProgressModel.ahbpId : self.passengerProgressRecordInfoModel.ahbpId;
        NSInteger houseType = self.houseProgressModel ? 1 : self.passengerProgressRecordInfoModel.tradeBusinessType;
        if (houseType == 2) ahbpId = self.passengerProgressRecordInfoModel.ahrId;
        
        [kNetworkManager requestProgressSellerImportantNotiInfoWithAhbpId:ahbpId success:^(SISSSellerImportantNotiModel *sellerImportantNotiModel) {
            
            weakSelf.sellerImportantNotiModel = sellerImportantNotiModel;
            weakSelf.uploadImageShowView.imageUrlArr = sellerImportantNotiModel.image.mutableCopy;
            weakSelf.remarkView.rightStr = sellerImportantNotiModel.otherdesc;
            weakSelf.createDateView.rightStr = sellerImportantNotiModel.insertTime;
            
        } failed:^(NSError *error) {
            NSLog(@"%@",error);
        }];
    } else {
        NSString *adbpId = self.passengerProgressModel ? self.passengerProgressModel.adbpId : self.houseProgressRecordInfoModel.adbpId;
        NSInteger demandType = self.passengerProgressModel ? 1 : self.houseProgressRecordInfoModel.tradeBusinessType;
        if (demandType == 2) adbpId = self.houseProgressRecordInfoModel.abdId;
        NSDictionary *parameters = @{
                                     @"adbpId" : adbpId
                                     };
        [kNetworkManager requestrProgressBuyerImportantNotiInfoWithParameters:parameters success:^(SISSBuyerImportantNotiModel *buyerImportantNotiModel) {
            
            weakSelf.buyerImportantNotiModel = buyerImportantNotiModel;
            weakSelf.uploadImageShowView.imageUrlArr = buyerImportantNotiModel.image.mutableCopy;
            weakSelf.remarkView.rightStr = buyerImportantNotiModel.otherdesc;
            weakSelf.createDateView.rightStr = buyerImportantNotiModel.insertTime;
            
        } failed:^(NSError *error) {
            NSLog(@"%@",error);
        }];
    }
    
}

- (void)modifyButtonClickAction {
    
    SISSUploadImportantMattersNotiViewController *vc = [[SISSUploadImportantMattersNotiViewController alloc] init];
    vc.isSellerNoti = self.isSellerNoti;
    vc.sellerImportantNotiModel = self.sellerImportantNotiModel;
    vc.buyerImportantNotiModel = self.buyerImportantNotiModel;
    vc.houseProgressModel = self.houseProgressModel;
    vc.houseProgressRecordInfoModel = self.houseProgressRecordInfoModel;
    vc.passengerProgressModel = self.passengerProgressModel;
    vc.passengerProgressRecordInfoModel = self.passengerProgressRecordInfoModel;
    [self.navigationController pushViewController:vc animated:YES];
}

@end
